package com.riekoff.particlecubeworld.player;

import cc.creativecomputing.graphics.CCColor;
import cc.creativecomputing.graphics.texture.CCPixelType;
import cc.creativecomputing.graphics.texture.CCTexture.CCTextureFilter;
import cc.creativecomputing.graphics.texture.CCTexture3D;
import cc.creativecomputing.graphics.texture.CCTextureAttributes;
import cc.creativecomputing.graphics.texture.CCTextureData;
import cc.creativecomputing.graphics.texture.CCTextureIO;
import cc.creativecomputing.io.CCIOUtil;
import cc.creativecomputing.math.CCVector3f;
import cc.creativecomputing.math.CCVector3i;
import cc.creativecomputing.util.logging.CCLog;

public class AZones {

	private CCTexture3D _myZoneTexture;
	private CCVector3f[] _myZoneInfos;
	
	public AZones(String[] theFolders){
		CCTextureAttributes myAttributes = new CCTextureAttributes();
		myAttributes.generateMipmaps(false);
		myAttributes.pixelType(CCPixelType.UNSIGNED_BYTE);
		_myZoneTexture = new CCTexture3D(myAttributes, 1000, 1000, 120);
		_myZoneTexture.textureFilter(CCTextureFilter.NEAREST);
		
		String[] myFolders = theFolders;
		
		_myZoneInfos = new CCVector3f[100];
		int myIndex = 0;
		
		CCTextureData myStartData = new CCTextureData(100, 100);
		for(int x = 0; x < 100; x++){
			for(int y = 0; y < 100; y++){
				myStartData.setPixel(x, y, new CCColor(1f,0f,0f));
			}
		}
		
		for(String myFolder : myFolders){
			int x = myIndex % 10 * 100;
			int y = myIndex / 10 * 100;
			
			String[] myFiles = CCIOUtil.list(myFolder,"png");
			
			_myZoneInfos[myIndex] = new CCVector3f();
			_myZoneInfos[myIndex].z = myFiles.length;
			for(int i = 0; i < myFiles.length && i < 120;i++) {
				String myFile = myFolder +"/" + myFiles[i];
				CCTextureData myData = CCTextureIO.newTextureData(myFile);
				_myZoneTexture.updateData(myStartData, x, y, i);
				_myZoneTexture.updateData(myData, x, y, i);

				_myZoneInfos[myIndex].x = myData.width();
				_myZoneInfos[myIndex].y = myData.height();
			}
			
			CCLog.info(myIndex + " : " + _myZoneInfos[myIndex]);
			myIndex++;
		}
		for(; myIndex < 100;myIndex++) {

			int x = myIndex % 10 * 100;
			int y = myIndex / 10 * 100;
			_myZoneTexture.updateData(myStartData, x, y, 0);
		}
	}
	
	public CCTexture3D texture(){
		return _myZoneTexture;
	}
	
	public CCVector3f[] zoneInfos(){
		return _myZoneInfos;
	}
}
